Ext.require(['AM.service.WorkSpace', 'AM.service.Thumbnails']);


Ext.define('AM.service.Setting', {

    singleton:true,


    rotate:function (deg) {
        var dom = ppt.cache.rightClickDom;
        var rotate_str = 'rotate(' + deg + 'deg)';
        var newValue = null;
        var value = dom.style['-webkit-transform'];
        if (value == 'none' || value == null || value == '' || value.indexOf('scale') == -1) {
            newValue = rotate_str;
        }
        else {
            if (value.indexOf('rotate') == -1) {
                newValue = value + ' ' + rotate_str;
            }
            else {
                newValue = value.replace(/rotate\(\d+deg\)/, rotate_str);
            }
        }
        dom.style['-webkit-transform'] = newValue;
        AM.service.Thumbnails.refresh(ppt.index);
    },


    backgroundColor:function (color) {
        var dom = ppt.cache.rightClickDom;
        dom.style['background-color'] = color;
        dom.style['background-image'] = '';
        AM.service.Thumbnails.refresh(ppt.index);
    },


    backgroundImage:function (url) {
        var dom = ppt.cache.rightClickDom;
        dom.style['background-image'] = 'url(' + url + ')'
        AM.service.Thumbnails.refresh(ppt.index);
    },


    scale:function (times) {
        var dom = ppt.cache.rightClickDom;
        //  dom.style.webkitTransformOriginX = 0;
        //   dom.style.webkitTransformOriginY = 0;
        var scale_str = 'scale(' + times + ')';
        var newValue = null;
        var value = dom.style['-webkit-transform'];
        if (value == 'none' || value == null || value == '' || value.indexOf('rotate') == -1) {
            newValue = scale_str;
        }
        else {
            if (value.indexOf('scale') == -1) {
                newValue = value + ' ' + scale_str;
            }
            else {
                newValue = value.replace(/scale\(.+\)/, scale_str);
            }
        }
        dom.style['-webkit-transform'] = newValue;

        AM.service.Thumbnails.refresh(ppt.index);
    },


    scaleBorder:function () {
        var dom = ppt.cache.rightClickDom;
        dom.style.width = '';
        dom.style.height = '';
        AM.service.Thumbnails.refresh(ppt.index);
    },


    opacity:function (value) {
        var dom = ppt.cache.rightClickDom;
        dom.style.opacity = value;
        AM.service.Thumbnails.refresh(ppt.index);
    },

    src:function (url) {
        var dom = ppt.cache.rightClickDom;
        dom.src = url;
        AM.service.Thumbnails.refresh(ppt.index);
    },


    width:function (width) {
        var dom = ppt.cache.rightClickDom;
        dom.style.width = width + 'px';
        AM.service.Thumbnails.refresh(ppt.index);
    },


    height:function (height) {
        var dom = ppt.cache.rightClickDom;
        dom.style.height = height + 'px';
        AM.service.Thumbnails.refresh(ppt.index);
    },


    disableDrag:function () {
        var dom = ppt.cache.rightClickDom;
        dom.contentEditable = true;

        var cmp = Ext.getCmp(dom.id);
        cmp.dd.disable();
    },


    enableDrag:function () {
        var dom = ppt.cache.rightClickDom;
        var cmp = Ext.getCmp(dom.id);
        cmp.dd.enable();
    },


    anim:function (animName) {
        var dom = ppt.cache.rightClickDom;
        var cmp = Ext.getCmp(dom.id);

        cmp.animName = animName;
    },


    zIndex:function (zIndex) {
        var dom = ppt.cache.rightClickDom;

        dom.style.zIndex = zIndex;
        AM.service.Thumbnails.refresh(ppt.index);
    },


    cutOverAudio:function (name) {
        var page = ppt.view.workspace.items.get(ppt.index);
        page.cutOverAudioName = name;
    },


    delete: function(){
        var dom = ppt.cache.rightClickDom;
        var cmp = Ext.getCmp(dom.id);

        Ext.destroy(cmp);
        delete cmp;
        AM.service.Thumbnails.refresh(ppt.index);
    },


    deletePage: function() {
        AM.service.WorkSpace.deletePage();
    }
})